
Page({
    data: {
      result: {},
      showResult: [],
      type: 'principalAndInteres',
      tabArray: ['等额本息', '等额本金'],
      tabIndex: 0,
    },
    onLoad(t) {
      // const tpage = getCurrentPages();
      // const thisPageUrl = tpage[tpage.length - 1].route;
      // console.log(tpage, thisPageUrl)
      let res = wx.getStorageSync('_mortgage');
      if (res) {
        let params = {}
        switch (t.type) {
          case 'principal': // 本金
            params.showResult = JSON.parse(res).principal.info
            break;
          default: // 所有
            params.showResult = JSON.parse(res).principalAndInteres.info
            break;
        }
        this.setData({
          result: JSON.parse(res),
          type: t.type || 'principalAndInteres',
          ...params
        })
      } else {
        console.warn('Not Data!!!');
        wx.redirectTo({ url: '/page/mortgage/mortgage' });
      }
    },
    onReady() {},
    onShow() {},
    onHide() {},
    onUnload() {},
    onPullDownRefresh() {},
    onReachBottom() {},
    onShareAppMessage() {},
    chooseTabBar(e) { // 切换显示页
      let target = e.currentTarget.dataset;
      if (target.index !== this.data.tabIndex) {
        this.setData({
          tabIndex: Number(target.index),
          showResult: target.index == 0 ? this.data.result.principalAndInteres.info : this.data.result.principal.info
        })
      }
    },
  })
